package com.integral.controller;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.integral.biz.IBankExchangeRateBiz;
import com.integral.entity.BankExchangeRate;
import com.integral.entity.UserInfo;
import com.integral.vo.BankExchangeRateVo;

@Controller
@RequestMapping("/bankExchangeRate")
public class BankExchangeRateController {

	@Resource
	private IBankExchangeRateBiz bankExchangeRateBiz;
	
	/**
	 * 查询银行汇率列表
	 * @param bankExchangeRateVo
	 * @return
	 */
	@RequestMapping(value="/findBankExchangeRate")
	@ResponseBody
	public Map<String,Object> findBankExchangeRate(BankExchangeRateVo bankExchangeRateVo){
		//设置查询未删除数据
		bankExchangeRateVo.setDeleteFlag(0);
		List<BankExchangeRateVo> list = bankExchangeRateBiz.findBankExchangeRate(bankExchangeRateVo);
		
		Map<String,Object> map = new HashMap<String,Object>();
		map.put("total", bankExchangeRateBiz.findBankExchangeRateCount(bankExchangeRateVo));
		map.put("rows", list);
		return map;
	}
	/**
	 * 新增银行汇率
	 * @param bankExchangeRateVo
	 * @return
	 */
	@RequestMapping(value="/addBankExchangeRate")
	public String addBankExchangeRate(BankExchangeRateVo bankExchangeRateVo){
		BankExchangeRate bankExchangeRate = new BankExchangeRate();
		bankExchangeRate.setBankCode(bankExchangeRateVo.getBankCode());
		bankExchangeRate.setBankExchangeRate(bankExchangeRateVo.getBankExchangeRate());
		bankExchangeRate.setUserTypeCode(bankExchangeRateVo.getUserTypeCode());
		
		bankExchangeRateBiz.addBankExchangeRate(bankExchangeRate);
		return "management/bankExchangeRate";
	}
	/**
	 * 删除汇率信息
	 * @param id
	 * @return
	 */
	@RequestMapping(value="/delbankExchangeRate")
	@ResponseBody
	public String delbankExchangeRate(HttpServletRequest request,Integer id){
		//获取登录对象
		HttpSession session = request.getSession();
		UserInfo user = (UserInfo)session.getAttribute("userInfo");
		
		BankExchangeRate bankExchangeRate = new BankExchangeRate();
		bankExchangeRate.setId(id);
		bankExchangeRate.setDeleteFlag(1);
		bankExchangeRate.setUpdateTime(new Date());
		bankExchangeRate.setUpdateEmp(user.getUserName());
		int i = bankExchangeRateBiz.updateBankExchangeRate(bankExchangeRate);
		if(i > 0){
			return "删除成功！";
		}else{
			return "删除失败！";
		}
	}
	/**
	 * 修改银行汇率
	 * @param bankExchangeRateVo
	 * @return
	 */
	@RequestMapping(value="updateBankExchangeRate")
	@ResponseBody
	public String updateBankExchangeRate(HttpServletRequest request,BankExchangeRateVo bankExchangeRateVo){
		HttpSession session = request.getSession();
		UserInfo user = (UserInfo)session.getAttribute("userInfo");
		BankExchangeRate bankExchangeRate = new BankExchangeRate();
		bankExchangeRate.setId(bankExchangeRateVo.getId());
		bankExchangeRate.setBankCode(bankExchangeRateVo.getBankCode());
		bankExchangeRate.setBankExchangeRate(bankExchangeRateVo.getBankExchangeRate());
		bankExchangeRate.setUserTypeCode(bankExchangeRateVo.getUserTypeCode());
		bankExchangeRate.setUpdateTime(new Date());
		bankExchangeRate.setUpdateEmp(user.getUserName());
		int i = bankExchangeRateBiz.updateBankExchangeRate(bankExchangeRate);
		if(i > 0){
			return "修改成功！";
		}else{
			return "修改失败！";
		}
	}
}
